//
//  FeedbackAddSucceedView.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/7/4.
//

#import "FeedbackAddSucceedView.h"

@interface FeedbackAddSucceedView()
@property(nonatomic,strong)UIView *bgView;
@end

@implementation FeedbackAddSucceedView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        self.currentAvailableWidth = frame.size.width;
        self.currentAvailableHeight = frame.size.height;
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    __weak typeof(self)weakSelf = self;
    self.backgroundColor = UIColorHex_(0x000000,0.6);
    CGFloat bg_w = 280;
    if(self.currentAvailableWidth < 312){
        bg_w = self.currentAvailableWidth-32;
    }
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.cornerRadius = 10;
    bgView.layer.masksToBounds = YES;
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(bg_w);
        make.height.mas_equalTo(@260);
        make.centerX.mas_equalTo(weakSelf);
        make.centerY.mas_equalTo(weakSelf);
    }];
    self.bgView = bgView;
    
    UIButton *closeBtn = [[UIButton alloc]init];
    [closeBtn setImage:[UIImage imageNamed:@"feeback_success_close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@30);
        make.right.mas_equalTo(@-7);
        make.top.mas_equalTo(@7);
    }];
    UIImageView *logoImageView = [[UIImageView alloc]init];
    logoImageView.image = [UIImage imageNamed:@"feeback_success_logo"];
    [bgView addSubview:logoImageView];
    [logoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(@200);
        make.height.mas_equalTo(@133);
        make.centerX.mas_equalTo(bgView);
        make.top.mas_equalTo(@26);
    }];
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.font = JPUIFontPingFangSCMedium(16);
    titleLabel.textColor = KFontBlackColor;
    titleLabel.text = @"提交成功！";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(logoImageView.mas_bottom).offset(9);
        make.height.mas_equalTo(@22);
        make.centerX.mas_equalTo(bgView);
    }];
    UILabel *tipLabel = [[UILabel alloc]init];
    tipLabel.font = JPUIFontPingFangSCRegular(13);
    tipLabel.textColor = KFontGrayColor;
    tipLabel.text = @"感谢您对日语岛内容质量的监督\n我们将尽快核实并处理～";
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.numberOfLines = 2;
    [bgView addSubview:tipLabel];
    [tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(@40);
        make.right.mas_equalTo(@-40);
    }];
    
    
}

-(void)refreshWidth{
    CGFloat bg_w = 280;
    if(self.currentAvailableWidth < 312){
        bg_w = self.currentAvailableWidth-32;
    }
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(bg_w);
    }];
}

-(void)closeBtnClick{
    if(_closeBlock){
        _closeBlock();
    }
}

@end
